<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JS027-本地存储</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    body {
        background-color: #222;
        color: snow;
    }

</style>
<body>
<script>
    localStorage.setItem('key', 'value');
    console.log(localStorage.getItem('key')); //value
    localStorage.removeItem('key');

    const anchorTo = {uname: 'api', age: '33', gender: 'male'};
    console.log(anchorTo);
    sessionStorage.setItem('anchor', JSON.stringify(anchorTo));
    const anchorFrom = JSON.parse(sessionStorage.getItem('anchor'));
    console.log(anchorFrom);
</script>
</body>
</html>